package impl;

import anaydis.sort.SorterType;

import java.util.Comparator;
import java.util.List;

public abstract class AbstractQuickSorter extends AbstractSorter {

    protected AbstractQuickSorter(SorterType type) {
        super(type);
    }

    protected <T> int partition(Comparator<T> comparator, List<T> list, int left, int right) {
        int inicio = left; int fin = right;
        int w = inicio - 1;
        int v = fin;

        while (true) {
            while (greater(comparator, list, fin, ++w)){
                if (w == fin)  break;
            }
            while (greater(comparator, list, --v, fin)){
                if (v <= inicio) break;
            }
            if ((v <= w)){
                swap(list, w, fin);
                break;
            } else{
                swap(list, w, v);
            }
        }
            return w;}
}
